package com.shop2cn.iapi.agentproducts.testcase;

import java.io.IOException;
import java.text.DecimalFormat;
import java.text.NumberFormat;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

import org.apache.http.client.ClientProtocolException;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.shop2cn.iapi.agentproducts.parameter.AddAgentProductBean;
import com.shop2cn.iapi.agentproducts.parameter.AddProductBean;
import com.shop2cn.iapi.agentproducts.parameter.DetailsAgentPriceDto;
import com.shop2cn.iapi.agentproducts.parameter.ProductDetailsDto;
import com.shop2cn.iapi.agentproducts.parameter.ProductListDto;
import com.shop2cn.iapi.agentproducts.parameter.UpdateProductBaseBean;
import com.shop2cn.iapi.agentproducts.service.UpdateProductBaseCall;
import com.ymatou.iapi.godfreightmgr.parameter.CreateCollectionGoodsAddressBean;
import com.ymatou.iapi.godfreightmgr.parameter.CreateFreightTemplateBean;
import com.ymatou.iapi.godmch.parameter.createDepotBean;
import com.ymatou.iapi.godmch.parameter.setConditionMarkupConfigBean;
import com.ymatou.iapi.prodstock.parameter.AgentProductPo;
import com.ymatou.mq.admin.parameter.MessageListBean;
import com.ymt.core.tool.FormatUtil;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.TestCase;
import com.ymt.utils.annotation.TestSuite;
import com.ymt.utils.tag.P1;
import com.ymttest.business.service.AddAgentProductCallService;
import com.ymttest.business.service.AgentProductCallService;
import com.ymttest.business.service.GodfreightmgrService;
import com.ymttest.business.service.MqQueryCallService;
import com.ymttest.business.service.shenqi.GodmchManageCallService;
import com.ymttest.database.model.YmtProductsI;
import com.ymttest.database.model.godmch.mch_depot_info;
import com.ymttest.database.sqlwapper.YmtProductsIWapper;
import com.ymttest.utils.AgentUsers;
import com.ymttest.utils.TestDataManager;
/**
*更新商品基础信息Test
*FreeMaker Template自动生成代码
*/
@TestSuite
public class Ts_UpdateProductBase{
	private static UpdateProductBaseBean updateproductbaseBean;
	private static UpdateProductBaseCall updateproductbaseCall;
	private static YmtProductsIWapper ymtProductsIWapper = new YmtProductsIWapper();
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("更新商品基础信息Test");
	}

	@Before
	public void caseUp() {
		updateproductbaseBean=new UpdateProductBaseBean();
		updateproductbaseCall=new UpdateProductBaseCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(updateproductbaseCall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	
	
	// vip渠道
	private static int vipRootUserId = AgentUsers.vipRootUserId;
	private static String vipRootUserName = "NickautoTest";
	private static int csId = AgentUsers.csId;
	// vip渠道->代理
	private static int vipAgentUserId1 = AgentUsers.vipAgentUserId1;
	private static String vipAgentUserName1 = "dgsq408897016";
	private static int csId1 = AgentUsers.csId1;
	// vip渠道->代理->代理
	private static int vipAgentUserId2 = AgentUsers.vipAgentUserId2;
	private static String vipAgentUserName2 = "NickautoTest";
	
	
	
	
	public void verifyMongoCurMq(String pid) throws ClientProtocolException, IOException, InterruptedException {
		Thread.sleep(5000);
		MessageListBean MessageListBean2 = MqQueryCallService.initAgentMongoCrud(pid);
		List<Map> joa2 = MqQueryCallService.GetMqMessage(MessageListBean2);
		Logger.debug(joa2);
		int redo = 0;
		while (joa2.size() < 2 && redo < 3) {
			Thread.sleep(5000);
			joa2 = MqQueryCallService.GetMqMessage(MessageListBean2);
			redo++;
		}
		String actionType = "ModifyAgentProduct";
		String appId = "agentproducts.iapi.ymatou.com";
		Logger.verifyEquals(actionType, joa2.get(0).get("ActionType"), "验证ActionType");
		Logger.verifyEquals(pid, joa2.get(0).get("ProductId"), "验证ProductId");
		Logger.verifyEquals(appId, joa2.get(0).get("AppId"), "验证AppId");
	}
	
	
	public void verifyMongoCurMq1(String pid) throws ClientProtocolException, IOException, InterruptedException {
		Thread.sleep(5000);
		MessageListBean MessageListBean2 = MqQueryCallService.initAgentMongoCrud(pid);
		List<Map> joa2 = MqQueryCallService.GetMqMessage(MessageListBean2);
		Logger.debug(joa2);
		int redo = 0;
		while (joa2.size() < 2 && redo < 3) {
			Thread.sleep(5000);
			joa2 = MqQueryCallService.GetMqMessage(MessageListBean2);
			redo++;
		}
		String actionType = "ModifyAllAgentProductSellPrice";
		String appId = "agentproducts.iapi.ymatou.com";
		Logger.verifyEquals(actionType, joa2.get(0).get("ActionType"), "验证ActionType");
		Logger.verifyEquals(pid, joa2.get(0).get("ProductId"), "验证ProductId");
		Logger.verifyEquals(appId, joa2.get(0).get("AppId"), "验证AppId");
	}
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_UpdateProductBase_001() {
		Logger.start(true,"修改标题，成功");
		try {
			AddProductBean initAddProduct = AddAgentProductCallService.initAddProduct(vipRootUserId, vipRootUserName, true);
			String addProduct = AddAgentProductCallService.AddProduct(initAddProduct);
			updateproductbaseBean = AddAgentProductCallService.initUpdateProductBase(addProduct, initAddProduct);
			updateproductbaseBean.setTitle("修改标题测试"+TestDataManager.getRandomNum(6));
			updateproductbaseBean.setSaleType(2);
//			updateproductbaseBean.setFreightTemplateName("测试运费模板18399");
			updateproductbaseCall.setData(updateproductbaseBean);
			updateproductbaseCall.callService();			
			Logger.verifyEquals("200", updateproductbaseCall.getString("code"), "验证code");
			Thread.sleep(5000);
			verifyMongoCurMq(addProduct);
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_UpdateProductBase_002() {
		Logger.start(true,"没填用户id，失败");
		try {
			AddProductBean initAddProduct = AddAgentProductCallService.initAddProduct(vipRootUserId, vipRootUserName, true);
			String addProduct = AddAgentProductCallService.AddProduct(initAddProduct);
			updateproductbaseBean = AddAgentProductCallService.initUpdateProductBase(addProduct, initAddProduct);
			updateproductbaseBean.setTitle("修改标题测试"+TestDataManager.getRandomNum(6));
			updateproductbaseBean.setUserId(null);
			updateproductbaseBean.setSaleType(2);
			
			updateproductbaseCall.setData(updateproductbaseBean);
			updateproductbaseCall.callService();			
			Logger.verifyEquals("400", updateproductbaseCall.getString("code"), "验证code");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_UpdateProductBase_003() {
		Logger.start(true,"没填商品id，失败");
		try {
			AddProductBean initAddProduct = AddAgentProductCallService.initAddProduct(vipRootUserId, vipRootUserName, true);
			String addProduct = AddAgentProductCallService.AddProduct(initAddProduct);
			updateproductbaseBean = AddAgentProductCallService.initUpdateProductBase(addProduct, initAddProduct);
			updateproductbaseBean.setTitle("修改标题测试"+TestDataManager.getRandomNum(6));
			updateproductbaseBean.setProductId(null);
			updateproductbaseBean.setSaleType(2);
			updateproductbaseCall.setData(updateproductbaseBean);
			updateproductbaseCall.callService();			
			Logger.verifyEquals("400", updateproductbaseCall.getString("code"), "验证code");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_UpdateProductBase_004() {
		Logger.start(true,"没填用户标题，失败");
		try {
			AddProductBean initAddProduct = AddAgentProductCallService.initAddProduct(vipRootUserId, vipRootUserName, true);
			String addProduct = AddAgentProductCallService.AddProduct(initAddProduct);
			updateproductbaseBean = AddAgentProductCallService.initUpdateProductBase(addProduct, initAddProduct);
			updateproductbaseBean.setTitle(null);
			updateproductbaseBean.setSaleType(2);
			updateproductbaseCall.setData(updateproductbaseBean);
			updateproductbaseCall.callService();			
			Logger.verifyEquals("400", updateproductbaseCall.getString("code"), "验证code");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_UpdateProductBase_005() {
		Logger.start(true,"没填上架类型，失败");
		try {
			AddProductBean initAddProduct = AddAgentProductCallService.initAddProduct(vipRootUserId, vipRootUserName, true);
			String addProduct = AddAgentProductCallService.AddProduct(initAddProduct);
			updateproductbaseBean = AddAgentProductCallService.initUpdateProductBase(addProduct, initAddProduct);
			updateproductbaseBean.setSaleType(null);
			updateproductbaseCall.setData(updateproductbaseBean);
			updateproductbaseCall.callService();			
			Logger.verifyEquals("400", updateproductbaseCall.getString("code"), "验证code");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_UpdateProductBase_006() {
		Logger.start(true,"模板名称不存在，失败");
		try {
			AddProductBean initAddProduct = AddAgentProductCallService.initAddProduct(vipRootUserId, vipRootUserName, true);
			String addProduct = AddAgentProductCallService.AddProduct(initAddProduct);
			updateproductbaseBean = AddAgentProductCallService.initUpdateProductBase(addProduct, initAddProduct);
			updateproductbaseBean.setTitle("修改标题测试"+TestDataManager.getRandomNum(6));
			updateproductbaseBean.setSaleType(2);
			updateproductbaseBean.setFreightTemplateName("不存在的模板名称");
			updateproductbaseCall.setData(updateproductbaseBean);
			updateproductbaseCall.callService();			
			Logger.verifyEquals("400", updateproductbaseCall.getString("code"), "验证code");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_UpdateProductBase_007() {
		Logger.start(true,"修改币种，发送ModifyAllAgentProductSellPrice指令");
		try {
			AddProductBean initAddProduct = AddAgentProductCallService.initAddProduct(vipRootUserId, vipRootUserName, true);
			String addProduct = AddAgentProductCallService.AddProduct(initAddProduct);
			updateproductbaseBean = AddAgentProductCallService.initUpdateProductBase(addProduct, initAddProduct);
			updateproductbaseBean.setTitle("修改标题测试"+TestDataManager.getRandomNum(6));
			updateproductbaseBean.setSaleType(2);
			updateproductbaseBean.setCurrency("CNY");
			updateproductbaseCall.setData(updateproductbaseBean);
			updateproductbaseCall.callService();			
			Logger.verifyEquals("200", updateproductbaseCall.getString("code"), "验证code");
			
			Thread.sleep(5000);
			
			verifyMongoCurMq1(addProduct);
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_UpdateProductBase_008() {
		Logger.start(true,"修改商品仓库");
		try {
			AddProductBean initAddProduct = AddAgentProductCallService.initAddProduct(vipRootUserId, vipRootUserName,
					true);
			createDepotBean createDepot = GodmchManageCallService.createDepot(vipRootUserId);
			List<mch_depot_info> Depots = GodmchManageCallService.SelectDepotByMchIdAndSuccess(vipRootUserId);
			initAddProduct.setDepotName(Depots.get(0).getDepotTitle());
			String addProduct = AddAgentProductCallService.AddProduct(initAddProduct);
			updateproductbaseBean = AddAgentProductCallService.initUpdateProductBase(addProduct, initAddProduct);
			updateproductbaseBean.setDepotName(Depots.get(1).getDepotTitle());
			updateproductbaseCall.setData(updateproductbaseBean);
			updateproductbaseCall.callService();			
			Logger.verifyEquals("200", updateproductbaseCall.getString("code"), "验证code");
			Thread.sleep(5000);
			verifyMongoCurMq(addProduct);
			
			YmtProductsI ymtProductsI = new YmtProductsIWapper().selectProductByProductId(addProduct).get(0);
			Logger.verifyEquals(ymtProductsI.getiBondedArea(), Depots.get(1).getDepotId(), "验证仓库");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
	@Test 
	@Category({P1.class})
	@TestCase
	public void Tc_UpdateProductBase_009() {
		Logger.start(true,"修改之后，非必填字段不更新");
		try {
			AddProductBean initAddProduct = AddAgentProductCallService.initAddProduct(vipRootUserId, vipRootUserName, true);
			initAddProduct.setRemark("123123");
			String addProduct = AddAgentProductCallService.AddProduct(initAddProduct);
//			updateproductbaseBean = AddAgentProductCallService.initUpdateProductBase(addProduct, initAddProduct);
			updateproductbaseBean=new UpdateProductBaseBean();
			updateproductbaseBean.setUserId(vipRootUserId);
			updateproductbaseBean.setProductId(addProduct);
			updateproductbaseBean.setTitle("修改标题测试"+TestDataManager.getRandomNum(6));
			updateproductbaseBean.setSaleType(2);
			updateproductbaseCall.setData(updateproductbaseBean);
			updateproductbaseCall.callService();			
			Logger.verifyEquals("200", updateproductbaseCall.getString("code"), "验证code");
			
			Thread.sleep(5000);
			initAddProduct.setTitle(updateproductbaseBean.getTitle());
			initAddProduct.setSaleType(2);
			AgentProductCallService.checkAddProduct(addProduct, initAddProduct, false);
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
	@Test 
	@Category({P1.class})
	@TestCase
	public void Tc_UpdateProductBase_010() {
		Logger.start(true,"修改时，校验运费和商品币种一致");
		try {
			AddProductBean initAddProduct = AddAgentProductCallService.initAddProduct(vipRootUserId, vipRootUserName, true);
			initAddProduct.setRemark("123123");
			initAddProduct.setFreightTemplateName("测试运费模板18399");
			String addProduct = AddAgentProductCallService.AddProduct(initAddProduct);
//			updateproductbaseBean = AddAgentProductCallService.initUpdateProductBase(addProduct, initAddProduct);
			updateproductbaseBean=new UpdateProductBaseBean();
			updateproductbaseBean.setUserId(vipRootUserId);
			updateproductbaseBean.setProductId(addProduct);
			updateproductbaseBean.setTitle("修改标题测试"+TestDataManager.getRandomNum(6));
			updateproductbaseBean.setSaleType(2);
			updateproductbaseBean.setCurrency("CNY");
			updateproductbaseCall.setData(updateproductbaseBean);
			updateproductbaseCall.callService();			
			Logger.verifyEquals("201", updateproductbaseCall.getString("code"), "验证code");
			Logger.verifyEquals("商品币种、运费模板币种需一致", updateproductbaseCall.getString("message"), "验证code");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_UpdateProductBase_011() {
		Logger.start(true,"设置条件自动加价后修改品牌品类-验证取消自动加价标签");
		try {
			Integer mchId = GodmchManageCallService.CreateGodMch();
			Integer agenttype=GodmchManageCallService.getAgentType(mchId, 1);
			Integer agent_mchId = GodmchManageCallService.getAgentMchId(mchId, agenttype);
			createDepotBean bean=GodmchManageCallService.createDepot(mchId);
	        List<mch_depot_info> selectDepotByDepotTitle = GodmchManageCallService.SelectDepotByDepotTitle(bean.getDepotTitle());
			AddAgentProductBean addAgentProductBean = AddAgentProductCallService.initAddAgentProduct(mchId, "", true);
			addAgentProductBean.setDepotId(selectDepotByDepotTitle.get(0).getDepotId());
			
			
			String productId = AddAgentProductCallService.AddAgentProduct(addAgentProductBean);
			setConditionMarkupConfigBean setConditionMarkupConfigBean = GodmchManageCallService.initDefSetConditionMarkupConfig(agent_mchId, mchId, 1, addAgentProductBean, 1);
			GodmchManageCallService.SetConditionMarkupConfigCall(setConditionMarkupConfigBean);
			updateproductbaseBean = AddAgentProductCallService.initUpdateProductBase(productId, addAgentProductBean);
			updateproductbaseBean.setBrandId(AddAgentProductCallService.BrandId2);
			updateproductbaseCall.setData(updateproductbaseBean);
			updateproductbaseCall.callService();			
			Logger.verifyEquals("200", updateproductbaseCall.getString("code"), "验证code");
			Thread.sleep(3000);
			MessageListBean MessageListBean = MqQueryCallService.initMessageListBean("product", "sync_auto_markup", productId+"_"+mchId);
			List <Map> joa = MqQueryCallService.GetMqMessage(MessageListBean);
			if(joa.size()==0){
				Thread.sleep(5000);
				 joa = MqQueryCallService.GetMqMessage(MessageListBean);
			}
			joa.forEach(ele->{
				Logger.debug(ele.toString());
			});
			Logger.verifyEquals(true, joa.size()>0, "验证总线消息");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_UpdateProductBase_012() {
		Logger.start(true,"设置条件自动加价后修改分仓-验证取消自动加价标签");
		try {
			Integer mchId = GodmchManageCallService.CreateGodMch();
			Integer agenttype=GodmchManageCallService.getAgentType(mchId, 1);
			Integer agent_mchId = GodmchManageCallService.getAgentMchId(mchId, agenttype);
			createDepotBean bean=GodmchManageCallService.createDepot(mchId);
	        List<mch_depot_info> selectDepotByDepotTitle = GodmchManageCallService.SelectDepotByDepotTitle(bean.getDepotTitle());
			AddAgentProductBean addAgentProductBean = AddAgentProductCallService.initAddAgentProduct(mchId, "", true);
			addAgentProductBean.setDepotId(selectDepotByDepotTitle.get(0).getDepotId());
			String productId = AddAgentProductCallService.AddAgentProduct(addAgentProductBean);
			setConditionMarkupConfigBean setConditionMarkupConfigBean = GodmchManageCallService.initDefSetConditionMarkupConfig(agent_mchId, mchId, 1, addAgentProductBean, 1);
			GodmchManageCallService.SetConditionMarkupConfigCall(setConditionMarkupConfigBean);
			updateproductbaseBean = AddAgentProductCallService.initUpdateProductBase(productId, addAgentProductBean);
			
			//换一个分仓
			createDepotBean bean2=GodmchManageCallService.createDepot(mchId);
	        List<mch_depot_info> selectDepotByDepotTitle2 = GodmchManageCallService.SelectDepotByDepotTitle(bean2.getDepotTitle());
	        
			updateproductbaseBean.setDepotId(selectDepotByDepotTitle2.get(0).getDepotId());
			updateproductbaseCall.setData(updateproductbaseBean);
			updateproductbaseCall.callService();			
			Logger.verifyEquals("200", updateproductbaseCall.getString("code"), "验证code");
			Thread.sleep(3000);
			MessageListBean MessageListBean = MqQueryCallService.initMessageListBean("product", "sync_auto_markup", productId+"_"+mchId);
			List <Map> joa = MqQueryCallService.GetMqMessage(MessageListBean);
			if(joa.size()==0){
				Thread.sleep(5000);
				 joa = MqQueryCallService.GetMqMessage(MessageListBean);
			}
			joa.forEach(ele->{
				Logger.debug(ele.toString());
			});
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_UpdateProductBase_013() {
		Logger.start(true,"设置条件自动加价后修改类目-验证取消自动加价标签");
		try {
			Integer mchId = GodmchManageCallService.CreateGodMch();
			Integer agenttype=GodmchManageCallService.getAgentType(mchId, 1);
			Integer agent_mchId = GodmchManageCallService.getAgentMchId(mchId, agenttype);
			createDepotBean bean=GodmchManageCallService.createDepot(mchId);
	        List<mch_depot_info> selectDepotByDepotTitle = GodmchManageCallService.SelectDepotByDepotTitle(bean.getDepotTitle());
			AddAgentProductBean addAgentProductBean = AddAgentProductCallService.initAddAgentProduct(mchId, "", true);
			addAgentProductBean.setDepotId(selectDepotByDepotTitle.get(0).getDepotId());
			String productId = AddAgentProductCallService.AddAgentProduct(addAgentProductBean);
			setConditionMarkupConfigBean setConditionMarkupConfigBean = GodmchManageCallService.initDefSetConditionMarkupConfig(agent_mchId, mchId, 1, addAgentProductBean, 1);
			GodmchManageCallService.SetConditionMarkupConfigCall(setConditionMarkupConfigBean);
			List<ProductListDto> getProductLists2 = AddAgentProductCallService.GetProductLists(agent_mchId);
			  int redo=0;
			  while(getProductLists2.size()<1&&redo<3) {
				  Thread.sleep(5000);
				  redo++;
				  getProductLists2 = AddAgentProductCallService.GetProductLists(agent_mchId);
			  }
			ProductListDto agentProd = getProductLists2.get(0);
			//商品打标
			Logger.verifyEquals(agentProd.getAutoMarkupStatus(),1,"已经被打上自动加价的标");
			updateproductbaseBean = AddAgentProductCallService.initUpdateProductBase(productId, addAgentProductBean);
			//God_ProductCategory - 
			updateproductbaseBean.setThirdCategoryId(1117);
			updateproductbaseCall.setData(updateproductbaseBean);
			updateproductbaseCall.callService();			
			Logger.verifyEquals("200", updateproductbaseCall.getString("code"), "验证code");
			Thread.sleep(3000);
			 getProductLists2 = AddAgentProductCallService.GetProductLists(agent_mchId);
			   redo=0;
			  while(getProductLists2.size()<1&&redo<3) {
				  Thread.sleep(5000);
				  redo++;
				  getProductLists2 = AddAgentProductCallService.GetProductLists(agent_mchId);
			  }
			ProductListDto agentProd2 = getProductLists2.get(0);
			//商品打标
			Logger.verifyEquals(agentProd2.getAutoMarkupStatus(),-1,"已经被打上自动加价的标");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_UpdateProductBase_014() {
		Logger.start(true,"修改副标题，成功");
		try {
			AddProductBean initAddProduct = AddAgentProductCallService.initAddProduct(vipRootUserId, vipRootUserName, true);
			String productId = AddAgentProductCallService.AddProduct(initAddProduct);
			updateproductbaseBean = AddAgentProductCallService.initUpdateProductBase(productId, initAddProduct);
			updateproductbaseBean.setSubTitle("副标题"+TestDataManager.getRandomNum(6));
			updateproductbaseCall.setData(updateproductbaseBean);
			updateproductbaseCall.callService();			
			Logger.verifyEquals("200", updateproductbaseCall.getString("code"), "验证code");
			Thread.sleep(5000);
			AgentProductPo agentProductPo = ymtProductsIWapper.selectAgentProductByProductId(productId);
			Logger.verifyEquals(agentProductPo.getSubTitle(), updateproductbaseBean.getSubTitle(), "验证副标题");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_UpdateProductBase_015() {
		Logger.start(true,"运费模板是null则忽略修改");
		try {
			Integer vipRootUserId = GodmchManageCallService.CreateGodMch();
			
			AddProductBean initAddProduct = AddAgentProductCallService.initAddProduct(vipRootUserId, "", true);
			CreateFreightTemplateBean createFreightTemplateBean = GodfreightmgrService
					.initCreateFreightTemplate(vipRootUserId, 1, 2);
			String templateId = GodfreightmgrService.CreateFreightTemplate(createFreightTemplateBean);
			initAddProduct.setFreightTemplateName(createFreightTemplateBean.getTemplateName());
			String productId = AddAgentProductCallService.AddProduct(initAddProduct);
			updateproductbaseBean = AddAgentProductCallService.initUpdateProductBase(productId, initAddProduct);
			updateproductbaseBean.setFreightTemplateName(null);
			updateproductbaseCall.setData(updateproductbaseBean);
			updateproductbaseCall.callService();			
			Logger.verifyEquals("200", updateproductbaseCall.getString("code"), "验证code");
			Thread.sleep(5000);
			ProductDetailsDto selectProductDetails = AddAgentProductCallService.selectProductDetails(vipRootUserId, productId);
			Logger.verifyEquals(templateId, ""+selectProductDetails.getFreightTemplateId(), "验证运费模板未修改");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_UpdateProductBase_016() {
		Logger.start(true,"运费模板是null则忽略修改，空字符就是包邮");
		try {
			Integer vipRootUserId = GodmchManageCallService.CreateGodMch();
			AddProductBean initAddProduct = AddAgentProductCallService.initAddProduct(vipRootUserId, "", true);
			CreateFreightTemplateBean createFreightTemplateBean = GodfreightmgrService
					.initCreateFreightTemplate(vipRootUserId, 1, 2);
			String templateId = GodfreightmgrService.CreateFreightTemplate(createFreightTemplateBean);
			initAddProduct.setFreightTemplateName(createFreightTemplateBean.getTemplateName());
			String productId = AddAgentProductCallService.AddProduct(initAddProduct);
			updateproductbaseBean = AddAgentProductCallService.initUpdateProductBase(productId, initAddProduct);
			updateproductbaseBean.setFreightTemplateName("");
			updateproductbaseCall.setData(updateproductbaseBean);
			updateproductbaseCall.callService();			
			Logger.verifyEquals("200", updateproductbaseCall.getString("code"), "验证code");
			Thread.sleep(5000);
			ProductDetailsDto selectProductDetails = AddAgentProductCallService.selectProductDetails(vipRootUserId, productId);
			Logger.verifyEquals(0, selectProductDetails.getFreightTemplateId(), "验证运费模板被删除");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_UpdateProductBase_017() {
		Logger.start(true,"税率不填，应该保留原值,如果是0就是包税");
		try {
			Integer vipRootUserId = GodmchManageCallService.CreateGodMch();
			AddProductBean initAddProduct = AddAgentProductCallService.initAddProduct(vipRootUserId, "", true);
			initAddProduct.setTariffRate(9.1d);
			String productId = AddAgentProductCallService.AddProduct(initAddProduct);
			
			
			updateproductbaseBean = AddAgentProductCallService.initUpdateProductBase(productId, initAddProduct);
			Double tariffRate = updateproductbaseBean.getTariffRate();
			updateproductbaseBean.setTariffRate(null);
			updateproductbaseCall.setData(updateproductbaseBean);
			updateproductbaseCall.callService();			
			Logger.verifyEquals("200", updateproductbaseCall.getString("code"), "验证code");
			Thread.sleep(5000);
			YmtProductsI ymtProductsI = ymtProductsIWapper.selectProductByProductId(productId).get(0);
			AgentProductPo AgentProduct = ymtProductsIWapper.selectAgentProductByProductId(productId);
			Logger.verifyEquals(1,ymtProductsI.getiTariffType(),"税率null保留原值");
			Logger.verifyEquals(tariffRate*0.01,AgentProduct.getTariffRate().doubleValue(),"税率null保留原值");
			
			
			
			updateproductbaseBean.setTariffRate(0d);
			updateproductbaseCall.setData(updateproductbaseBean);
			updateproductbaseCall.callService();			
			Logger.verifyEquals("200", updateproductbaseCall.getString("code"), "验证code");
			Thread.sleep(5000);
			ymtProductsI = ymtProductsIWapper.selectProductByProductId(productId).get(0);
			AgentProduct = ymtProductsIWapper.selectAgentProductByProductId(productId);
			Logger.verifyEquals(0,ymtProductsI.getiTariffType(),"税率0包税");
			Logger.verifyEquals(0.0,AgentProduct.getTariffRate().doubleValue(),"税率0包税");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_UpdateProductBase_018() {
		Logger.start(true,"修改自提点，成功");
		try {
			Integer mchId_channl = GodmchManageCallService.CreateSellerMch();
			//开启运营
            GodfreightmgrService.setCollectionGoodsByAdminCall(mchId_channl, true);
            //添加一个自提地址
            CreateCollectionGoodsAddressBean createcollectiongoodsaddressBean = GodfreightmgrService.initCreateCollectionGoodsAddressBean(mchId_channl);
            int addressId = GodfreightmgrService.createcollectiongoodsaddressCall(createcollectiongoodsaddressBean);
            //开启自提
            GodfreightmgrService.setCollectionGoodsBySellerCall(mchId_channl, true);
            
			AddProductBean initAddProduct = AddAgentProductCallService.initAddProduct(mchId_channl, vipRootUserName, true);
			String productId = AddAgentProductCallService.AddProduct(initAddProduct);
			updateproductbaseBean = AddAgentProductCallService.initUpdateProductBase(productId, initAddProduct);
			updateproductbaseBean.setCollectionGoodsAddress(Arrays.asList(addressId));
			updateproductbaseCall.setData(updateproductbaseBean);
			updateproductbaseCall.callService();			
			Logger.verifyEquals("200", updateproductbaseCall.getString("code"), "验证code");
			Thread.sleep(5000);
			AgentProductPo agentProductPo = ymtProductsIWapper.selectAgentProductByProductId(productId);
//			Logger.debug(StringEscapeUtils.escapeJava(FormatUtil.beanToGSONString(updateproductbaseBean)));
//			Logger.verifyEquals(agentProductPo.getCollectionGoodsAddress(), String.join(',', updateproductbaseBean.getCollectionGoodsAddress()) , "验证自提点");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
	
	
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_UpdateProductBase_020() {
		Logger.start(true,"商品旅游类目无法更改为普通类目");
		try {
			int sellerId=AgentUsers.rootUserId;
			AddAgentProductBean addAgentProductBean = AddAgentProductCallService.initAddAgentProduct(sellerId,
					"", true);
			addAgentProductBean.setCategoryId(2661);
			addAgentProductBean.setThirdCategoryId(2662);
			String productId = AddAgentProductCallService.AddAgentProduct(addAgentProductBean);
			Thread.sleep(3000);
			YmtProductsI ymtProductsI = new YmtProductsIWapper().selectProductByProductId(productId).get(0);
			Logger.verifyEquals(8, ymtProductsI.getiCatalogStatus(), "物流方式改为了普通");
            
			updateproductbaseBean = AddAgentProductCallService.initUpdateProductBase(productId, addAgentProductBean);
			updateproductbaseBean.setThirdCategoryId(1003);
			updateproductbaseCall.setData(updateproductbaseBean);
			updateproductbaseCall.callService();			
			Logger.verifyEquals("201", updateproductbaseCall.getString("code"), "验证code");
			Logger.verifyEquals("酒店旅游类目暂不支持修改 ", updateproductbaseCall.getString("message"), "验证code");
			Thread.sleep(1000);

			ymtProductsI = new YmtProductsIWapper().selectProductByProductId(productId).get(0);
			Logger.verifyEquals(8, ymtProductsI.getiCatalogStatus(), "物流方式改为了普通");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_UpdateProductBase_021() {
		Logger.start(true,"商品旅游类目无法更改为普通类目");
		try {
			int sellerId=AgentUsers.rootUserId;
			AddAgentProductBean addAgentProductBean = AddAgentProductCallService.initAddAgentProduct(sellerId,
					"", true);
			String productId = AddAgentProductCallService.AddAgentProduct(addAgentProductBean);
			Thread.sleep(3000);
			YmtProductsI ymtProductsI = new YmtProductsIWapper().selectProductByProductId(productId).get(0);
			Logger.verifyEquals(999, ymtProductsI.getiCatalogStatus(), "物流方式改为了普通");
            
			updateproductbaseBean = AddAgentProductCallService.initUpdateProductBase(productId, addAgentProductBean);
			updateproductbaseBean.setThirdCategoryId(2662);
			updateproductbaseCall.setData(updateproductbaseBean);
			updateproductbaseCall.callService();			
			Logger.verifyEquals("201", updateproductbaseCall.getString("code"), "验证code");
			Logger.verifyEquals("酒店旅游类目暂不支持修改 ", updateproductbaseCall.getString("message"), "验证code");
			Thread.sleep(1000);

			ymtProductsI = new YmtProductsIWapper().selectProductByProductId(productId).get(0);
			Logger.verifyEquals(999, ymtProductsI.getiCatalogStatus(), "物流方式改为了普通");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	

	public void verifyAgentPrice(Integer AgentId,String ProductId,double Percentage) throws ClientProtocolException, IOException{
		ProductDetailsDto productDetailsDto = AddAgentProductCallService.selectProductDetails(AgentId,
				ProductId);
		DetailsAgentPriceDto b = productDetailsDto.getAgentPriceList().get(1);
				b.getCatalogPriceList().forEach(c->{
					productDetailsDto.getCatalogList().forEach(d->{
						if(c.getCatalogId().equals(d.getCatalogId())){
							Logger.comment("验证"+d.getCatalogId()+"自动加价是否正确---到手代理价："+d.getAgentPrice()+"给下级代理价："+c.getAgentPrice());
							NumberFormat   nf=new  DecimalFormat( "0.0");
						    double dou = Double.parseDouble(nf.format(d.getAgentPrice()*(0.01*Percentage+1)));
							Logger.verifyEquals(dou, c.getAgentPrice(), "验证自动加价");
						}
					});
				});
			
	}
	
	public void verifyDB(AddProductBean AddProduct,UpdateProductBaseBean Bean) throws Exception{
		
		System.out.println(AddProduct+"-----"+Bean);
		System.out.println(Bean.getDepotId());
		if(Bean.getTitle()!=null){
			AddProduct.setTitle(Bean.getTitle());
		}
		if(Bean.getThirdCategoryId()!=null){
			AddProduct.setThirdCategoryId(Bean.getThirdCategoryId());
		}
		if(Bean.getBrandId()!=null){
			System.out.println(666);
			AddProduct.setBrandId(Bean.getBrandId());
		}
		if(Bean.getCatalogStatus()!=null){
			System.out.println();
			AddProduct.setCatalogStatus(Bean.getCatalogStatus());
		}
		if(Bean.getCardInfo()!=null){
			AddProduct.setCardInfo(Bean.getCardInfo());
		}
		if(Bean.getCurrency()!=null){
			AddProduct.setCurrency(Bean.getCurrency());
		}
		if(Bean.getRemark()!=null){
			AddProduct.setRemark(Bean.getRemark());
		}
		if(Bean.getTariffRate()!=null){
			AddProduct.setTariffRate(Bean.getTariffRate());
		}
		if(Bean.getMarketCurrency()!=null){
			AddProduct.setMarketCurrency(Bean.getMarketCurrency());
		}
		if(Bean.getFreightTemplateName()!=null){
			AddProduct.setFreightTemplateName(Bean.getFreightTemplateName());
		}
		if(Bean.getSaleType()!=null){
			AddProduct.setSaleType(Bean.getSaleType());
		}
		if(Bean.getDepotName()!=null){
			AddProduct.setDepotName(Bean.getDepotName());
		}
		
		
		AgentProductCallService.checkAddProduct(Bean.getProductId(), AddProduct, false);
		
		
	}
	
}